#requests库
#作用发送http请求,获得响应 是第三方模块
# 向url发送get请求 response = requests.get(url)
# 打印响应内容 response.text response.content.decode() content是二进制内容,decode负责解码
# response.url 响应的url 有时候请求和响应的url不一样
# response.status_code 状态响应码
# response.request.headers 响应对应的请求头
# response.headers 响应头
# response.request._cookies 响应对应的请求cookie
# response.cookies 响应的cookie
import requests
url = "https://www.baidu.com/"
response = requests.get(url)
# print(response.text) #响应内容有乱码,text会自动寻找一种方式去解码
# print(response.content.decode(encoding="utf-8"))

#保存响应内容
#保存一张图片
#获取url
url = "https://tse2-mm.cn.bing.net/th/id/OIP-C.dWynPR3Y2M9oHnLvFEbdTwHaQB?w=115&h=180&c=7&r=0&o=7&cb=thvnext&dpr=1.5&pid=1.7&rm=3"
#发送请求,获取响应
response = requests.get(url)
print(response.content)
#保存响应
with open("1.png","wb") as f:
    f.write(response.content)
